/*
 * =====================================================================================
 *
 *       Filename:  sigaction.cpp
 *
 *    Description:  
 *
 *        Version:  1.0
 *        Created:  03/29/2011 05:19:55 AM
 *       Revision:  none
 *       Compiler:  gcc
 *
 *         Author:  Chen Ken (Ken), zlchen.ken@gmail.com
 *        Company:  EMC
 *
 * =====================================================================================
 */
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>

#define handle_error(msg) \
	do { perror(msg); exit(EXIT_FAILURE); } while (0)

char *buffer;
int flag=0;

static void handler(int sig, siginfo_t *si, void *unused)
{
    printf("Got SIGSEGV at address: 0x%lx\n",(long) si->si_addr);
    printf("Implements the handler only\n");
    flag=1;
    exit(EXIT_FAILURE);
}

int main(int argc, char *argv[])
{
  char *p; char a;
  int pagesize;
  struct sigaction sa;

  sa.sa_flags = SA_SIGINFO;
  sigemptyset(&sa.sa_mask);
  sa.sa_sigaction = handler;
  if (sigaction(SIGSEGV, &sa, NULL) == -1)
     handle_error("sigaction");

  int* intp = NULL;
  *intp = 0;
}
